package cn.kgc.itrip.auth.controller;

import cn.kgc.itrip.auth.service.IUserService;
import cn.kgc.itrip.auth.service.TokenService;
import cn.kgc.itrip.beans.common.ServerResponse;
import cn.kgc.itrip.beans.model.vo.ItripUserVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @author 阿泽
 */
@Controller
@RequestMapping("/api")
public class UserController {
    @Resource
    IUserService iUserService;
    @Resource
    TokenService tokenService;

    /**
     * 判断账户是否存在
     */
    @RequestMapping(value = "/ckusr", method = RequestMethod.GET)
    @ResponseBody
    public ServerResponse ckusr(String name) {
        ServerResponse serverResponse = iUserService.checkUserCode(name);
        return serverResponse;
    }

    /**
     * 手机注册
     *
     * @param user
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/registerbyphone", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse registerbyphone(@RequestBody ItripUserVo user) throws Exception {
        return iUserService.addUser(user, 2);
    }


    @RequestMapping(value = "/validatephone", method = RequestMethod.PUT)
    @ResponseBody
    public ServerResponse validatephone(String user, String code) {
        return iUserService.activation(user, code);
    }

    @RequestMapping(value = "/activate", method = RequestMethod.PUT)
    @ResponseBody
    public ServerResponse activate(String user, String code) {
        ServerResponse serverResponse = iUserService.activation(user, code);
        return serverResponse;
    }

    @RequestMapping(value = "/doregister", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse doregister(@RequestBody ItripUserVo user) throws Exception {
        ServerResponse serverResponse = iUserService.addUser(user,1);
        return serverResponse;
    }

}
